

// 删除链表中的倒数第N个节点(一趟扫描实现)

struct ListNode* removeNthFromEnd(struct ListNode* head, int n){
    struct ListNode *dummy = malloc(sizeof(*dummy));
	struct ListNode *L, *R;
    dummy->next = head;
    L = R = dummy;

    for (int i = 0; i < n + 1; i++)
        R = R->next;
    while (R) {
        L = L->next;
        R = R->next;
    }

    // 删除目标节点
    struct ListNode *del = L->next;
    L->next = del->next;
    free(del);

    // 删除虚拟节点
    struct ListNode *res = dummy->next;
    free(dummy);
    return res;
}   